var CaseSelectionExplanation = {
    id: "caseSelectionExplanationTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

CaseSelectionExplanation.initColumn = function () {
    var columns =
        [
            {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '标签', field: 'label', align: 'center', valign: 'middle', sortable: true},
            {title: '内容', field: 'content', align: 'center', valign: 'middle', sortable: true,},
            {title: '排序', field: 'num', align: 'center', valign: 'middle', sortable: true,},
        ];
    return columns;
};

CaseSelectionExplanation.addExplanation = function () {
    var index = layer.open({
        type: 2,
        title: '添加评选说明',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/caseSelectionExplanation/to_add'
    });
    this.layerIndex = index;
};

CaseSelectionExplanation.updateExplanation = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '修改评选说明',
            area: ['100%', '100%'], //宽高
            fix: true, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/caseSelectionExplanation/to_edit/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

CaseSelectionExplanation.deleteExplanation = function () {
    if (this.check()) {
        var id= this.seItem.id;
            $.ajax({
                url: Feng.ctxPath + '/caseSelectionExplanation/delete/' + id,
                type: "post",
                data: {
                    id: id
                },
                success: function (data) {
                        Feng.success('操作成功!');
                        window.CaseSelectionExplanation.search();
                },
                error: function (data) {
                    alert('没有权限，请联系管理员!');
                }
            });
    }
};

CaseSelectionExplanation.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

/**
 * 查询预约客户列表
 */
CaseSelectionExplanation.search = function () {
    CaseSelectionExplanation.table.refresh({query: CaseSelectionExplanation.formParams()});
};

/**
 * 新市场预约表单查询提交参数
 */
CaseSelectionExplanation.formParams = function () {
    var queryData = {};
    queryData['label'] = $("#label").val();
    return queryData;
};

/**
 * 检查是否选中
 */
CaseSelectionExplanation.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CaseSelectionExplanation.seItem = selected[0];
        return true;
    }
};

/**
 * 重置
 */
CaseSelectionExplanation.resetSearch = function () {
    $("#caseSelectionPublic", parent.document).val("");
    $("#label").val("");
    CaseSelectionExplanation.search();
};

/**
 * 主页搜索
 */
$("#caseSelectionSearchAll", parent.document).click(function () {
    CaseSelectionExplanation.search();
});

var scollPostion = 0;
/**
 * 获取表格滚动到什么地方
 */
CaseSelectionExplanation.getScrollPosition = function () {
    scollPostion = $('#CaseSelection').bootstrapTable('getScrollPosition');
};

/**
 * 指定表格滚动到什么地方
 */
CaseSelectionExplanation.scrollTo = function () {
    $("#CaseSelection").on('load-success.bs.table', function (data) {
        $('#CaseSelection').bootstrapTable('scrollTo', scollPostion);
    });
};

$(function () {
    var defaultColunms = CaseSelectionExplanation.initColumn();
    var table = new BSTable(CaseSelectionExplanation.id, "/caseSelectionExplanation/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(CaseSelectionExplanation.formParams());
    CaseSelectionExplanation.table = table.init();
    $(document).on('click', '#laydate_clear,#laydate_today,#laydate_ok', function () {
        CaseSelectionExplanation.search()
    });
    callbackTable = function () {
        CaseSelectionExplanation.search()
    };
});